/**
 * 
 */
package com.li.shanlin.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author liyinlong
 *
 *         2017年3月14日下午1:09:12
 */
@Controller
@RequestMapping("/vue")
public class VueController {
	@RequestMapping("/helloworld")
	public String hellworld(HttpServletRequest request) {
		request.setAttribute("title", "这就是个thymleaf模板上传文件的");
		return "sss";
	}

	@RequestMapping("/print")
	@ResponseBody
	public String printaa(@RequestParam("file") MultipartFile file, @RequestParam String filename,
			HttpServletRequest request) {
		String path = request.getSession().getServletContext().getRealPath("static/upload/");

		if (!new File(path).exists()) {
			new File(path).mkdirs();
		}
		String fileName = file.getOriginalFilename();
		System.out.println(path);
		File targetFile = new File(path, fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}

		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "上传成功！";
	}
}
